<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>充值卡列表</title>
    <link rel="stylesheet" type="text/css" href='<c:url context="${pageContext.request.contextPath}" value="/easyui/themes/default/easyui.css"/>'>
    <link rel="stylesheet" type="text/css" href='<c:url context="${pageContext.request.contextPath}" value="/easyui/themes/icon.css"/>'>
    <link rel="stylesheet" type="text/css" href='<c:url context="${pageContext.request.contextPath}" value="/easyui/css/demo.css"/>'>
    <script type="text/javascript" src='<c:url context="${pageContext.request.contextPath}" value="/easyui/jquery.min.js"/>'></script>
    <script type="text/javascript" src='<c:url context="${pageContext.request.contextPath}" value="/easyui/jquery.easyui.min.js"/>'></script>
    <script type="text/javascript" src='<c:url context="${pageContext.request.contextPath}" value="/easyui/js/validateExtends.js"/>'></script>
    <script type="text/javascript" src='<c:url context="${pageContext.request.contextPath}" value="/easyui/js/easyui-lang-zh_CN.js"/>'></script>

    <script type="text/javascript">
        $(function() {
            //datagrid初始化
            $('#dataList').datagrid({//返回json数据后会自动填充到表格
                title:'充值卡列表',
                iconCls:'icon-more',//图标
                border: true,
                collapsible: false,//是否可折叠的
                fit: true,//自动大小
                method: "get",
                url:"reCharge?action=data&t="+new Date().getTime(),//到courseList页面后会自动发出此请求，数据自动填充
                idField:'id',//每行唯一的标识符
                singleSelect: true,//是否单选
                pagination: false,//分页控g件
                rownumbers: true,//行号
                sortName:'rid',
                sortOrder:'asc',
                remoteSort: false,
                columns: [[
                    {field:'chk',checkbox: true,width:50},//多选框
                    {field:'rid',title:'充值卡编号',width:50, sortable: true},
                    {field:'cardNumber',title:'卡号',width:200},
                    {field:'startDate',title:'开始时间',width:200},
                    {field:'endDate',title:'到期时间',width:200},
                    {field:'enabled',title:'卡状态',width:200},
                ]],
                toolbar: "#toolbar"
            });

            //设置工具类按钮
            $("#add").click(function(){
                $("#addDialog").dialog("open");
            });
            //删除
            $("#delete").click(function(){
                var selectRow = $("#dataList").datagrid("getSelected");
                if(selectRow == null){
                    $.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
                } else{
                    var rid = selectRow.rid;
                    $.messager.confirm("消息提醒", "将删除与课程相关的所有数据，确认继续？", function(r){
                        if(r){
                            $.ajax({
                                type: "delete",
                                url: "reCharge?rid="+rid,
                                data: {rid: rid,flag:"only"},
                                success: function(msg){
                                    if(msg.status == 200){
                                        $.messager.alert("消息提醒",msg.msg,"info");
                                        //刷新表格
                                        $("#dataList").datagrid("reload");
                                        $("#dataList").datagrid("uncheckAll");
                                    } else{
                                        $.messager.alert("消息提醒",msg.msg,"warning");
                                        return;
                                    }
                                }
                            });
                        }
                    });
                }
            });
        });
    </script>
</head>
<body>
<!-- 数据列表 -->
<table id="dataList" cellspacing="0" cellpadding="0">

</table>
<!-- 工具栏 -->
<div id="toolbar">
    <div style="float: left;"><a id="add" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加</a></div>
    <div style="float: left;" class="datagrid-btn-separator"></div>
    <div><a id="delete" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-some-delete',plain:true">删除</a></div>
</div>

<!-- 添加数据窗口 -->
<div id="addDialog" style="padding: 10px">
    <form id="addForm" method="post">
        <table cellpadding="8" >
            <tr>
                <td>课程名称:</td>
                <td><input id="add_name" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="courseName" data-options="required:true, validType:'repeat_course', missingMessage:'不能为空'" /></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
